const my_sql = require('mysql')

module.exports = async(item) => {
    const conn = await my_sql.createConnection({
        host: 'localhost',
        user: 'root',
        password: 'root',
        database: 'nodejs',
    });

    conn.connect(async(err) => {
        try {
            console.log('connected as id ' + conn.threadId);
        } catch (err) {
            console.error('error connecting: ' + err.stack);
            return;
        }
    });
    let insertSQL = 'INSERT IGNORE INTO baidu_api values(?,?,?,?,?,?,?,?,?)';
    let insertParams = [item.date, item.time.toString().length == 9 ? item.time : '0' + item.time, item.price, item.volume, item.avgPrice, item.ccl,
        item.netChangeRatio, item.preClose, item.amount
    ];
    //console.log(insertParams[0])
    for (i in item) {
        await conn.query(insertSQL, insertParams)
        await console.log('is down')
    }
    await conn.end();
}